<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ include file="/common/taglibs.jsp"%>
     <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户添加</title>
<link rel="stylesheet" type="text/css" href="${ctx}/css/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/css/easyui/demo.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/css/easyui/default.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/css/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/js/scripts/uploadify.css">
	<script type="text/javascript" src="${ctx}/js/scripts/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/easyui/src/jquery.parser.js"></script>
	 <script type="text/javascript" src="${ctx}/js/scripts/JSONUtil.js"></script>
	 <script type="text/javascript" src="${ctx}/js/easyui/local/easyui-lang-zh_CN.js"></script>

	<script type="text/javascript" src="${ctx}/js/scripts/swfobject.js"></script>
    <script type="text/javascript" src="${ctx}/js/scripts/jquery.uploadify.v2.1.0.js"></script>
    <script type="text/javascript" src="${ctx}/js/scripts/jquery.edatagrid.js"></script>
    <script type="text/javascript" src="${ctx}/js/scripts/util.js"></script>
    <script type="text/javascript">
    // 保存后台返回上传照片的名称
    var fileNames="";
    // 保存返回上传照片的路径
    var filePaths="";
    
    $(function(){
			
          /*上传*/
          $("#file_upload").uploadify({
            "uploader" : "${ctx}/uswf/uploadify.swf",
            "script" : "${ctx}/common/doUpload.jsp",
            "cancelImg" : "${ctx}/js/scripts/cancel.png",
            "folder" : "${ctx}/uploads/",
            "fileExt" : null,
            "fileDesc" : "Image Files",
            "sizeLimit" : 10240000,
            "auto" : false,
            "queueID" : "fileQueue",
            'formData' : {'jessionid':'<%=request.getSession().getId()%>'}, 
            "multi" : true,
            "buttonText" : "",
            "buttonImg" : "${ctx}/css/desc.gif",
            "width" : 50,
            "height" : 18,
            "onError" : function(event, ID, fileObj, errorObj) {

                //判断错误类型
                if (errorObj.type == "File Size") {
                  //提示信息
                  $.messager.alert("提示信息", "附件大小超过限制");
                  //删除超过大小的文件
                  $("#file_upload").uploadifyCancel(ID.replace("file_upload",""));
                }
              },
            "onComplete"  : function(event, ID, fileObj, response, data) {
                var fileName=response.replace(/(\n[\s|\t]*\r*\n)/g, "\n");
                var filePath=fileObj.filePath;
                //返回的文件名称取得换行，空格
                var str1=response.replace(/(\n[\s|\t]*\r*\n)/g, "\n");
                var str2=str1.replace(/^[\n|\r\n]*|[\n|\r\n]*$/g,"");
                if (fileNames == "") {
                    fileNames = str2;
                  } else {
                    fileNames = fileNames + "," + str2;
                  }
                if (filePaths == "") {
                  filePaths = filePath;
                } else {
                  filePaths = filePaths + "," + filePath;
                }
            },
            "onAllComplete" : function(event, data) {
                  saveTraCommInvoice();
              }
          });
      });
    function save(){
    	if($("#fileQueue").text()==""){
            saveTraCommInvoice();
          }else{
            $("#file_upload").uploadifyUpload();
          }
    }
    
    // 附件删除
    var delComAttIds = "";
    function deleteComAtt(comAttId) {
      if (window.confirm("确定删除附件？"/* "确定删除附件?" */)) {
        if (delComAttIds == "") {
          delComAttIds = comAttId;
        } else {
          delComAttIds = delComAttIds + "," + comAttId;
        }
        $("#" + comAttId).hide();
      }
    }
    
	  /*保存工作分类信息*/
    function saveTraCommInvoice(){
      //验证非空
      var retVal = $("#addUser").form("validate");
      if(!retVal) {
        return false;
      } 
  
      //if (window.confirm("确定添加？")) {
        var formValues=$("#addUser").serializeArray();
        //附件名称
        formValues.push({name:"fileNames",value:fileNames});
        //附件路径
        formValues.push({name:"filePaths",value:filePaths});
        formValues.push({name:"delComAttIds",value:delComAttIds});
        $.post("${ctx}/user/add",formValues,function(data){
          if(data.info=="success"){
        	  $.messager.alert('系统提示', '保存成功', 'info', function(){
        		  opener.location.href=opener.location.href;
                  opener=null;
                  //window.returnValue = "success";
                  window.close();
        	  });
              //保存成功
              // $.messager.alert("提示","保存成功");
              
          }else{
              //保存失败
              $.messager.alert("保存失败","系统提示", "info",function(){
            	  $('#save').attr("disabled",true);
            	  });/* 保存失败 */
            
             
          }
      });
      
    }
    </script>
</head>
<body>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
     <tr>
        <td valign="top">
        <form id="addUser" name="addDetailForm" method="post">
        <input type="hidden"  name="id" id="id" value='${user.id}'/>
        <input type="hidden"  name="createDate" id="createDate" value='${user.createDate}'/>
        <input type="hidden"  name="updateDate" id="updateDate" value='${user.updateDate}'/>
         <table id="userContent" width="100%" cellpadding="1"
            cellspacing="0">
            <tr>
             <td colspan="6" class="t_sld l_sld r_sld dispHeader">
                <table cellpadding="2" cellspacing="2">
                 <tr>
                    <td class="dispHeader">用户添加  <!-- 基本头部 -->
                    </td>
                 </tr>
                </table>
             </td>
            </tr>

            <tr style="min-height: 25">
             
             
            
             <td class="t_sld l_sld dispT" width="15%">用户昵称</td>
             <td class="t_sld l_sld dispC" width="15%" >
               <input type="text" class="easyui-validatebox w12" required="true" id="nickname" name="nickname" value="${user.nickname}"  maxlength="21"/>
             </td>
              <td class="t_sld l_sld  dispT" width="15%">用户名</td>
             <td class="t_sld l_sld  " width="15%" >
             <input type="text" class="easyui-validatebox w10"  required="true" id="username" name="username" value="${user.username}"/>
             </td> 
             <td class="t_sld l_sld dispT" width="15%"></td><!-- 工作分类编码 -->
             <td class="t_sld l_sld dispC r_sld dispC" width="15%" >
             </tr>
            <tr style="min-height: 25">
            
             
             <td class="t_sld l_sld dispTT" width="15%">密码</td>
             <td class="t_sld l_sld dispC" width="15%" >
               <input type="text" class="easyui-validatebox w12" required="true" id="password" name="password" value="${user.password}"  maxlength="21"/>
             </td>
              <td class="t_sld l_sld  dispTT" width="15%">是否可用</td>
             <td class="t_sld l_sld   dispC" width="15%" >
             <input type="text" class="easyui-validatebox w10"  required="true" id="status" name="status" value="Y"/>
             </td> 
              <td class="t_sld l_sld dispTT" width="15%"></td><!-- 工作分类编码 -->
             <td class="t_sld l_sld  r_sld dispC" width="15%" > 
             </td>
             </tr>
             
         		
         	
              <tr height="25">
              <td class=" l_sld  dispTT l_sld t_sld" width="15%" >附件<!-- 附件 --></td>
              <td class=" l_sld  r_sld dispC l_sld t_sld" width="15%"  colspan="5">
                <input id="file_upload" name="file_upload" type="file"/><div id="fileQueue" name="fileQueue"></div>
              </td>
            </tr> 
             <tr height="25">
                <td class="t_sld  l_sld dispTT " width="15%">已上传附件<!-- 已上传附件 --></td>
                <td class="t_sld  l_sld dispC r_sld " colspan="5">&nbsp;
                  <c:forEach var="comAtt" items="${comAttachments}">
                    <div id="${comAtt.attaId}">
                    ${comAtt.attaName}&nbsp;<a href="javascript:deleteComAtt('${comAtt.attaId}')">删除<!-- 删除 --></a>&nbsp;&nbsp;<a href="javascript:downLoadFile('${comAtt.attaId}')">下载<!-- 下载 --></a><br/>
                    </div>
                  </c:forEach>
                </td>
              </tr>
               <tr>
                  <td class="t_sld l_sld  b_sld dispT" width="15%" >邮箱</td>
                  <td class="t_sld l_sld b_sld r_sld dispC" width="15%" colspan="5" >
                    <textarea  id="email" name="email" class="easyui-validatebox w10" validType="length[0,500]" rows ="2" cols ="90" >${user.email}</textarea>
                  </td>
              </tr>
            <tr><td height="3" colspan="6" ></td></tr>
          </table>
      </form>
      </td>
      </tr>
      <tr><td height="8px" colspan="2"></td></tr>
      <tr>
        <td align="center" valign="bottom">
          <a href="#" id="save" class="easyui-linkbutton" iconCls="icon-save" plain="false" onclick="save()">保存</a><!-- 保存 -->
        </td>
      </tr>
    </table>
</body>
</html>